package com.mobile.collect.fragments;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mobile.collect.R;
import com.mobile.collect.activitys.BackUpActivity;
import com.mobile.collect.activitys.ExportListActivity;
import com.mobile.collect.activitys.LoginActivity;
import com.mobile.collect.activitys.QuanxianEditActivity;
import com.mobile.collect.activitys.UploadListActivity;
import com.mobile.collect.present.SettingPresent;
import com.mobile.collect.utils.AppContents;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.droidlover.xdroidmvp.cache.SharedPref;
import cn.droidlover.xdroidmvp.kit.Kits;
import cn.droidlover.xdroidmvp.mvp.XFragment;

public class SettingFragment extends XFragment<SettingPresent> {


    Unbinder unbinder;
    @BindView(R.id.txt_version)
    TextView txtVersion;


    @Override
    public int getContentViewId() {
        return R.layout.fragment_setting;
    }

    @Override
    public void getIntentData() {

    }


    @Override
    public void getDataFromServer() {
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);

    }

    @Override
    public void initView() {
        super.initView();
        txtVersion.setText("当前版本：" + Kits.Package.getVersionName(getActivity()));
    }

    @Override
    public void twinkCompleted() {

    }


    @Override
    public SettingPresent newP() {
        return new SettingPresent();
    }


    @Override
    public boolean showNoDataPage() {
        return true;
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != Activity.RESULT_OK) {
            return;
        }

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @Override
    public boolean isNotWorkConnect() {
        return false;
    }

    @OnClick({R.id.btn_export, R.id.btn_upload, R.id.btn_quit, R.id.qunxianLayout, R.id.beifenLayout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_export:
                startActivity(new Intent(getActivity(), ExportListActivity.class));
                break;
            case R.id.btn_quit:
                startActivity(new Intent(getActivity(), LoginActivity.class));
                break;
            case R.id.qunxianLayout:
                QuanxianEditActivity.lunch(getActivity());
                break;
            case R.id.beifenLayout:
                startActivity(new Intent(getActivity(),BackUpActivity.class));
                break;
            case R.id.btn_upload:
                String userName = SharedPref.getInstance(getActivity()).getString(AppContents.LOGINNAME, "");
                if (TextUtils.isEmpty(userName)) {
                    LoginActivity.lunch(getActivity());
                    break;
                } else {
                    startActivity(new Intent(getActivity(), UploadListActivity.class));
                }
                break;
        }
    }
//
//    private void export() {
//        showLoadDialog();
//        Observable.create(new Observable.OnSubscribe<Object>() {
//            @Override
//            public void call(Subscriber<? super Object> subscriber) {
//                ExportUtil2 exportUtil = new ExportUtil2(getActivity());
//                exportUtil.start();
//                subscriber.onNext(1);
//            }
//        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Object>() {
//            @Override
//            public void onCompleted() {
//
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                disLoadDialog();
//                e.printStackTrace();
//            }
//
//            @Override
//            public void onNext(Object o) {
//                disLoadDialog();
//                TipDialog.show(getActivity(), "导出完成", TipDialog.TYPE.SUCCESS);
//                NLog.e("ExportUtil", "onNextonNextonNext");
//            }
//        });
//    }


}
